//
//  CompanyTotalVC.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "CompanyTotalVC.h"
#import "CompanyTotalCell.h"
#import "CouponManagerVC.h"
#import "CertificateManagerVC.h"
#import "WithdrawFirstVC.h"
#import "OrderVC.h"

@interface CompanyTotalVC ()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UILabel *titleLab;

@property (nonatomic, copy) NSArray *titleArr;
@end

@implementation CompanyTotalVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.titleArr = @[@"优惠券管理", @"车辆GPS", @"订单管理", @"账户提现", @"证书管理"];
    self.fd_prefersNavigationBarHidden = YES;
    [self setUI];
    
}

- (void) setUI {
    self.view.backgroundColor = ColorF5;

    [self createTopView];
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(kTopHeight+11);
        make.leading.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.width.mas_equalTo(kScreenW);
    }];
    self.isRemoveHeader = YES;
    self.tableView.backgroundColor = ClearColor;
    [self.tableView registerClass:[CompanyTotalCell class] forCellReuseIdentifier:@"CompanyTotalCell"];
}

- (void) createTopView {
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(kScreenW, (64+kTopHeight)) direction:IHGradientChangeDirectionVertical startColor:[[UIColor colorWithHexString:@"FF5533"] colorWithAlphaComponent:1] endColor:[UIColor colorWithHexString:@"F5F5F5"]];
    [self.view addSubview:topView];
    [self.view sendSubviewToBack:topView];
    self.topView = topView;
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.view);
        make.height.mas_equalTo((64+kTopHeight));
    }];

//    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [backBtn setImage:[UIImage imageNamed:@"all_back_white"] forState:UIControlStateNormal];
//    [topView addSubview:backBtn];
//    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(topView).offset(kToolHeight+12);
//        make.leading.equalTo(topView).offset(15);
//    }];
//    backBtn.block = ^(UIButton *sender) {
//        [self.navigationController popViewControllerAnimated:YES];
//    };
//
//    UILabel *titleLab = [[UILabel alloc] init];
//    titleLab.textAlignment = NSTextAlignmentCenter;
//    titleLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
//    titleLab.textColor = WhiteColor;
//    [topView addSubview:titleLab];
//    self.titleLab = titleLab;
//    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(topView);
//        make.top.equalTo(topView).offset(kToolHeight+12);
//        make.leading.equalTo(topView).offset(80);
//    }];

    PButton *companyBtn = [PButton buttonWithType:UIButtonTypeCustom];
    [companyBtn setImage:[UIImage imageNamed:@"home_ic_arrow"] forState:UIControlStateNormal];
    [companyBtn setTitle:@"请选择" forState:UIControlStateNormal];
    [companyBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    companyBtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
    companyBtn.imagePosition = SPButtonImagePositionRight;
    [topView addSubview:companyBtn];
    [companyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView).offset(kToolHeight+12);
        make.leading.equalTo(topView).offset(15);
    }];

}

#pragma mark tableView

-  (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.titleArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CompanyTotalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CompanyTotalCell"];
    cell.titleLab.text = self.titleArr[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = ClearColor;
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        CouponManagerVC *vc = [[CouponManagerVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }

    if (indexPath.section == 2) {
        OrderVC *vc = [[OrderVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }

    if (indexPath.section == 3) {
        WithdrawFirstVC *vc = [[WithdrawFirstVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }

    if (indexPath.section == 4) {
        CertificateManagerVC *vc = [[CertificateManagerVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
